package org.example.dao.test;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.Document;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;

import java.util.List;

/**
 * @author yuntao.shen
 * @date 2018/12/19
 */
public class BatchInsertPlugin extends PluginAdapter {

    @Override
    public boolean validate(List<String> list) {
        return true;
    }

    @Override
    public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
        super.sqlMapDocumentGenerated(document, introspectedTable);
        XmlElement xe = new XmlElement("insert");
        xe.addAttribute(new Attribute("id", "batchInsert"));

        xe.addElement(new TextElement("INSERT INTO " + introspectedTable.getFullyQualifiedTableNameAtRuntime() + "("));

        List<IntrospectedColumn> is = introspectedTable.getAllColumns();

        for(IntrospectedColumn ic : is){
            xe.addElement(new TextElement("<if test=\"\""));
        }


        return true;
    }
}
